package quickcore.webview;

import android.Manifest;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.net.http.SslError;
import android.util.Log;
import android.webkit.SslErrorHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebViewClientImpl extends WebViewClient{


    private WebViewListener listener;
    public WebViewClientImpl(WebViewListener listener) {
        this.listener = listener;
    }
    //解决HTTPS链接问题
    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
        handler.proceed();
    }
    //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        Uri uri = Uri.parse(url);
        String scheme = uri.getScheme();
        if(scheme.equals("http")||scheme.equals("https")){
            listener.loadUrl(view,true,scheme,url);
        }else{
            listener.loadUrl(view,false,scheme,url);
        }
        return true;
    }
}
